home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1425 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  64 lines

  1. Path: castle.nando.net!news
  2. From: actuary@nando.net   (Bill McCarthy)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: What the hell is THIS?!
  5. Date: 13 Jan 1996 20:50:04 GMT
  6. Organization: News & Observer Public Access
  7. Message-ID: <4d95ts$fi0@castle.nando.net>
  8. References: <4d6rgh$rfu@abel.cc.sunysb.edu>
  9. Reply-To: actuary@nando.net (Bill McCarthy)
  10. NNTP-Posting-Host: vyger217.nando.net
  11. X-Newsreader: IBM NewsReader/2 v1.2
  12.  
  13. In <4d6rgh$rfu@abel.cc.sunysb.edu>, bmadhusu@engws12.ic.sunysb.edu (Bommasamudram Madhusudan) writes:
  14. >hi guys;
  15. >
  16. >I'm going nuts trying to figure this out;
  17. >
  18. >Can someone explain what
  19. >
  20. >  int (*p)[3]  is?????
  21. >
  22. >  Is this an array of pointers to integers 
  23.  
  24. No, that would be "int *p[3];"
  25.  
  26. >
  27. >  OR
  28. >
  29. >  a pointer to an array of integers?? HELP!
  30.  
  31. Bingo!
  32.  
  33. >I can say things like:
  34. >
  35. >(*p)[0] = 3; for e.g, but when I print the value using:
  36. >
  37. > printf("%d",(*p)[0]) I get a core dump!
  38.  
  39. Interesting.  You can store to unallocated memory, but
  40. a fetch gives you a core dump.  Time for a new compiler
  41. and/or operating system.
  42.  
  43. The basic problem is that memory has only been allocated
  44. for a pointer to an array -- not for the array.  Try out the
  45. following:
  46.  
  47. #include <stdio.h>
  48.  
  49. int main( void )
  50. {
  51.     int    arr[3];
  52.     int    (*p)[3] = arr;
  53.  
  54.     (*p)[0] = 3;
  55.     printf("%d",(*p)[0]);
  56.  
  57.     return 0;
  58. }
  59.  
  60. Bill McCarthy
  61. actuary@nando.net
  62. Wendell, NC  USA
  63.  
  64.